package xxh;

import javax.swing.*;
import java.awt.*;

public class BookPanel extends JPanel {
    private String bookNo;
    private JLabel lblBookNo, lblBookName, lblAuthor, lblStock;
    private JCheckBox chkSelect;

    public BookPanel(String bookNo, String bookName, String author, int stock) {
        this.bookNo = bookNo;

        // 设置布局
        setLayout(new GridLayout(5, 1));
        setBorder(BorderFactory.createLineBorder(new Color(200, 200, 200), 1)); // 设置边框

        // 初始化标签并设置字体
        lblBookNo = new JLabel("编号：" + bookNo);
        lblBookName = new JLabel("书名: " + bookName);
        lblAuthor = new JLabel("作者: " + author);
        lblStock = new JLabel("库存: " + stock);

        Font labelFont = new Font("微软雅黑", Font.PLAIN, 14); // 设置字体为微软雅黑，大小为14
        lblBookNo.setFont(labelFont);
        lblBookName.setFont(labelFont);
        lblAuthor.setFont(labelFont);
        lblStock.setFont(labelFont);

        // 标签颜色
        lblBookNo.setForeground(new Color(80, 80, 80));
        lblBookName.setForeground(new Color(80, 80, 80));
        lblAuthor.setForeground(new Color(80, 80, 80));
        lblStock.setForeground(new Color(80, 80, 80));

        // 初始化选择框并设置字体
        chkSelect = new JCheckBox("选择借阅");
        chkSelect.setFont(new Font("微软雅黑", Font.PLAIN, 14)); // 设置字体为微软雅黑，大小为14
        chkSelect.setHorizontalAlignment(SwingConstants.CENTER);

        // 设置复选框颜色
        chkSelect.setForeground(new Color(0, 123, 255));
        chkSelect.setFocusPainted(false);

        // 添加组件
        add(lblBookNo);
        add(lblBookName);
        add(lblAuthor);
        add(lblStock);
        add(chkSelect);

        // 设置每个BookPanel的固定大小
        setPreferredSize(new Dimension(180, 220));
    }

    public boolean isSelected() {
        return chkSelect.isSelected();
    }

    public String getBookNo() {
        return bookNo;
    }
}
